package com.wonderful.wedding.mapper;

import com.wonderful.wedding.model.Person;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface GroupPersonMappingMapper {

    @Select("SELECT * FROM group_person_mapping LEFT JOIN person ON person.id = group_person_mapping.person_id " +
        "WHERE group_person_mapping.group_id = #{group_id} AND group_person_mapping.person_id = #{person_id}")
    @Results(value = {
        @Result(column="person.id", property="id"),
        @Result(column="person.name", property="name"),
    })
    public Person findByGroupAndPerson(@Param("group_id")int groupId, @Param("person_id")int personId);

    @Select("INSERT INTO group_person_mapping (group_id, person_id) VALUES (#{group_id}, #{person_id})")
    int create(@Param("group_id")int groupId, @Param("person_id")int personId);
}
